getCarInfo = function (url) {
    var success = function (data) {
        if (data.success === true) {
            var carInfo = data.data;
            var formatter = carInfo['formatter'];
            $('#carId').val(carInfo['newCarId']);
            for (var i in formatter) {
                for (var index in formatter[i]) {
                    $('#' + index).val(formatter[i][index]);
                }
            }
        } else if (data.success === false) {
            layer.msg(data.message);
        }
    };
    ajax('post', url, '', success)
};


//检测ip
checkId = function(url) {
    if (!(check_null('carId'))) {
        return false;
    } else {
        $.ajax({
            url: url,
            type: "post",
            data: {"carId": $("#carId").val()},
            success: function (data) {
                if (data === true) {
                    $("#nameError").html("该小车名已存在！");
                    $("#nameError").focus();
                    return false;
                } else {
                    $("#nameError").html("");
                    return true;
                }
            }
        });
    }
};

$("#carId").change(function () {
    checkId();
});

function checkaCount() {
    var double = $("#aisDouble").val();
    var aCount = $("#aCount").val();
    if (!check_null('aCount') || !check_num('aCount')) {
        $("#aCountError").html("请输入纯数字！");
        $("#aCountError").focus();
        return false;
    }
    if(double === 'yes' && aCount%2){
        $("#aCountError").html("双面情况,每层站位需要双数！");
        return false;
    }else{
        $("#aCountError").html("");
        return true;
    }
}

function checkbCount() {
    var double = $("#bisDouble").val();
    var bCount = $("#bCount").val();
    if (!check_null('bCount') || !check_num('bCount')) {
        $("#bCountError").html("请输入纯数字！");
        $("#bCountError").focus();
        return false;
    }
    if(double === 'yes' && bCount%2){
        $("#bCountError").html("双面情况,每层站位需要双数！");
        return false;
    } else {
        $("#bCountError").html("");
        return true;
    }
}

function checkcCount() {
    var double = $("#cisDouble").val();
    var cCount = $("#cCount").val();
    if (!check_null('cCount') || !check_num('cCount')) {
        $("#cCountError").html("请输入纯数字！");
        $("#cCountError").focus();
        return false;
    }
    if(double === 'yes' && cCount%2){
        $("#cCountError").html("双面情况,每层站位需要双数！");
        return false;
    } else {
        $("#cCountError").html("");
        return true;
    }
}

function checkaRow() {
    if (!check_null('aCount') || !check_num('aRow')) {
        $("#aRowError").html("请输入纯数字！");
        $("#aRowError").focus();
        return false;
    } else {
        $("aRowError").html("");
        return true;
    }
}

function checkbRow() {
    if (!check_null('bCount') || !check_num('bRow')) {
        $("#bRowError").html("请输入纯数字！");
        $("#bRowError").focus();
        return false;
    } else {
        $("bRowError").html("");
        return true;
    }
}

function checkcRow() {
    if (!check_null('cCount') || !check_num('cRow')) {
        $("#cRowError").html("请输入纯数字！");
        $("#cRowError").focus();
        return false;
    } else {
        $("cRowErro").html("");
        return true;
    }
}

$("#aCount").change(function () {
    checkaCount();
});
$("#bCount").change(function () {
    checkbCount();
});
$("#cCount").change(function () {
    checkcCount();
});

$("#aRow").change(function () {
    check_num("aRow");
});
$("#bRow").change(function () {
    check_num("bRow");
});
$("#cRow").change(function () {
    check_num("cRow");
});
$("#aisDouble").change(function () {
    checkaCount();
});
$("#bisDouble").change(function () {
    checkbCount();
});
$("#cisDouble").change(function () {
    checkcCount();
});




$("#name").change(function () {
    check_name('name');
});

$("#submit").click(function () {
    return (check_name() && checkaCount() && checkbCount() && checkcCount() && checkaRow() && checkbRow() && checkcRow())
});
